class Solution:
    def isHappy(self, n: int) -> bool:
        def get_next(number):
            total_sum = 0
            while number > 0:
                # Return the tuple (x//y, x%y).
                number, digit = divmod(number, 10)
                total_sum = total_sum + digit ** 2
            return total_sum

        slow_number = n
        fast_number = get_next(n)
        while fast_number != 1 and fast_number != slow_number:
            slow_number = get_next(slow_number)
            fast_number = get_next(get_next(fast_number))
        return fast_number == 1


test_n = 19
res = Solution()
print(res.isHappy(test_n))
